package org.test.client.ui.content.table.bstable;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Stroke;

import javax.swing.border.AbstractBorder;

import org.test.client.ui.util.Icons;
import org.test.client.ui.util.UIUtil;

public  class MyLineBorder extends AbstractBorder{
	
	Color c = Icons.getColor("dddddd");
	int width = 1;
	boolean needRight = true;
	boolean needBottom = true;
	boolean needTop = true;
	boolean needLeft = true;
	
	public boolean needVerticalLine = true;
	
	public MyLineBorder(boolean needTop,boolean needRight, boolean needBottom, 
			boolean needLeft) {
		this.needTop = needTop;
		this.needRight = needRight;
		this.needBottom = needBottom;
		this.needLeft = needLeft;
	}


	@Override
	public void paintBorder(Component comp, Graphics g, int x, int y,
			int w, int h) {
		Graphics2D g2d = (Graphics2D) g;
		UIUtil.setAntiAliasing(g2d, true);
		Stroke stroke = UIUtil.getStroke(1);
		g2d.setStroke(stroke);
		g2d.setColor(c);
		if(needTop){
			//top
			g2d.drawLine(x, y, x+w, y);
		}
		if(needLeft && needVerticalLine){
			//left
			g2d.drawLine(x, y, x, y+h);
		}
		
		if(needRight && needVerticalLine){
			g2d.drawLine(x+w - 1, y, x+w - 1, y+h);
		}
		if(needBottom){
			g2d.drawLine(x, y+h-1, x+w, y+h-1);
		}
		
	}
	
	
	public Insets getInsets() {
		int top = width;
		int left = width*5;
		int right = 0;
		int bottom = 0;
		if(needRight){
			right = width;
		}
		if(needBottom){
			bottom = width;
		}
		return new Insets(top, right, bottom, left);
	}
}